<?php
class MyZendX_Form_Decorator_Uploadify extends Zend_Form_Decorator_Abstract
{
	public function render($content)
	{
		$element = $this->getElement();
		$view = $element->getView();
		if (!$view instanceof Zend_View_Interface) {
			return $content;
		}
		
		$class = $element->getAttrib('class');
		if (!is_array($class)) {
			$class = explode(' ', $class);			 
		}
		$class[] = $cls = 'js-zend-uploadify-' . $element->getId();
		$element->setAttrib('class', implode(' ', $class));

		$options = $element->getUploadifyOptions();
		if (!isset($options['mulit'])) {
			$options['multi'] = $element->isArray();
		}
		if (!isset($options['sizeLimit'])) {
			$options['sizeLimit'] = $element->getMaxFileSize();
		}
		
		$view->Uploadify('.'.$cls, $options);
		
		return $content;
	}
}